//
//  DoctorApplyController.m
//  KMedicine
//
//  Created by 曹牧 on 16/7/5.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "DoctorApplyController.h"
#import "ApplyMedicineNoteModel.h"
#import "ApplyMedicineNoteCell.h"
#import "DoctorInfoController.h"

@interface DoctorApplyController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray<ApplyMedicineNoteModel *> * notes;

@property (nonatomic,strong) UITableView * tableView ;
@end

@implementation DoctorApplyController

static NSString * identifier = @"noteCell";

#pragma mark -
#pragma mark - lazy
- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
    }
    return _tableView;
    
}

- (NSArray<ApplyMedicineNoteModel *> *)notes{
    
    if (!_notes) {
        _notes = [ApplyMedicineNoteModel applyMedicineNotes];
    }
    return _notes;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //注册类
    [self.tableView registerClass:[ApplyMedicineNoteCell class] forCellReuseIdentifier:identifier];
    //设置代理
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self setupUI];
    
}

- (void)setupUI{
    
    [self.view addSubview:self.tableView];

}

- (void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(self.view.frame.size);
        make.top.left.equalTo(self.view).offset(0);
    }];
}

#pragma mark -
#pragma mark - dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.notes.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ApplyMedicineNoteCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.model = self.notes[indexPath.row];
    return cell;
}

#pragma mark -
#pragma mark - delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DoctorInfoController * docInfoVc = [[DoctorInfoController alloc] init];
    docInfoVc.view.backgroundColor = [UIColor whiteColor];
    docInfoVc.model = self.notes[indexPath.row];
    
    [self.navigationController pushViewController:docInfoVc animated:YES];
    
    //取消选中该行
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
    
}

@end
